#!/usr/bin/perl

use strict;

sub encabezado(){
	print "="x80 ."\n";
}

my $mysqlconf=$ARGV[0];

my $mysqlversioncmd="/usr/libexec/mysqld -V";

my $logfile;
my $port;
my $datadir;

open(MYSQL_VERSION,$mysqlversioncmd." |");
print "MySQL version: ".<MYSQL_VERSION>;

open(MYSQL_CONF,$mysqlconf) or die "Cant read configuration file ";
my @mysqlconflines=<MYSQL_CONF>;

encabezado();
print "Comienzan las verificaciones de seguridad \n";
encabezado();

foreach my $line (@mysqlconflines){
	chomp $line;
	if( $line =~ /^\s*port\s*=\s*(.*)\s*$/){
		$port = $1;
		print "Puerto configurado: $port \n";
	}
	if( $line =~ /^\s*datadir\s*=\s*(.*)\s*$/){
		$datadir=$1;
		print "Directorio de datos mysql: $datadir \n";
	}
	if( $line =~ /^\s*skip-networking/){
		print $line . " habilitado -- OK\n";
	}
	if ( $line =~ /^\s*bind-address\s*=\s*127\.0\.0\.1/){
		print $line . " -- OK\n";
	}
	if ( $line =~ /^\s*set-variable\s*=\s*local-infile\s*=\s*0/){
		print $line . " -- OK\n";
	}
	if ( $line =~ /^\s*general-log\s*=/ ) {
		print $line . " -- OK \n";
	}
	if ( $line =~ /^\s*general-log-file\s*=\s*(.*)\s*$/ ) {
		$logfile=$1;
		print $line . " -- OK \n";
	}
}
encabezado();
print "Recomendaciones de seguridad \n";
encabezado();
